package com.dysoft.flesh.gl;

import com.dysoft.flesh.RenderContext;
import com.dysoft.flesh.Renderer;

import javax.media.opengl.GL;

/**
 * @author Sean Micklethwaite
 *         Oct 24, 2010 6:12:52 PM
 *
 * Renders a full-screen quad in orthographic projection, to fit
 * the size of the render target.
 */
public class GLPostProcessingRenderer extends GLOrthoProjection implements Renderer {

	public void render(RenderContext ctx) {
		int w = ctx.getTarget().getWidth(), h = ctx.getTarget().getHeight();
		GL gl = ((GLRenderer.GLRenderContext)ctx).getGL();

		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

		activate(ctx);

		gl.glPushMatrix();
        gl.glLoadIdentity();
        gl.glBegin(GL.GL_QUADS);
        gl.glTexCoord2d(0.0, 1.0);
        gl.glVertex2d(0, 0);
        gl.glTexCoord2d(0.0, 0.0);
        gl.glVertex2d(0, h);
        gl.glTexCoord2d(1.0, 0.0);
        gl.glVertex2d(w, h);
        gl.glTexCoord2d(1.0, 1.0);
        gl.glVertex2d(w, 0);
        gl.glEnd();
		gl.glPopMatrix();

		deactivate(ctx);
	}

}
